
var MY_INSTITUTION_DETAILS = (function() {

    var qrcode = new QRCode(document.getElementById("qrcodeTemp"), {
        // text: "http://www.baidu.com/",
        text: WeKnow.getRealPath()+"/evaluate.do?institutionId=" + $("#institutionId").val(),
        width: 250,
        height: 250,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });

    function loadInstitutionDetails(institutionId) {
        if (institutionId == undefined || institutionId.length == 0) {
            return;
        }
        $.ajax({
            type: "POST",
            url: "invs_institution_details.do/load_institution_details",
            data: {institutionId : institutionId},
            success: function(data) {
                WeKnow.closeLoading();
                if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

                if (data.errorcode == 0) {
                    //机构基本信息
                    drawBaseInfo(data.info.baseInfo);
                    //评分、评价
                    drawScoreInfo(data.info.scoreInfo);
                    //诊疗行为
                    drawPrescriptionSupervision(data.info.prescriptionSupervision);
                    //消毒灭菌
                    drawAccountSupervision(data.info.accountSupervision);
                    //自律自查
                    drawAutonomyExamination(data.info.autonomyExamination);
                    //行政处罚
                    drawPunish(data.info.punishCount);
                    //医师、护士列表
                    drawDoctorAndNurseTable(data.info.doctorList);
                } else if (data.errorcode == -1 ) {
                    WeKnow.errorMsg( data.errMsg );
                } else {
                    WeKnow.systemMsg('查询失败，请重新登录');
                }
            }
        });
    }

    //诊疗行为
    function loadPrescriptionDetails() {

        var parms = getYmdParams($('#preDtFrom'), $('#preDtTo'), 'yyyy-MM-dd');
        if (!parms) {
            return;
        }

        $.ajax({
            type: "POST",
            url: "invs_institution_details.do/load_prescription_details",
            data: parms,
            success: function(data) {
                WeKnow.closeLoading();
                if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

                if (data.errorcode == 0) {
                    //诊疗行为
                    drawPrescriptionSupervision(data.info.prescriptionSupervision);
                } else if (data.errorcode == -1 ) {
                    WeKnow.errorMsg( data.errMsg );
                } else {
                    WeKnow.systemMsg('查询失败，请重新登录');
                }
            }
        });
    }

    //消毒灭菌
    function loadAccountDetails() {

        var parms = getYmdParams($('#accDtFrom'), $('#accDtTo'), 'yyyy-MM-dd');
        if (!parms) {
            return;
        }

        $.ajax({
            type: "POST",
            url: "invs_institution_details.do/load_account_details",
            data: parms,
            success: function(data) {
                WeKnow.closeLoading();
                if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

                if (data.errorcode == 0) {
                    //消毒灭菌
                    drawAccountSupervision(data.info.accountSupervision);
                } else if (data.errorcode == -1 ) {
                    WeKnow.errorMsg( data.errMsg );
                } else {
                    WeKnow.systemMsg('查询失败，请重新登录');
                }
            }
        });
    }

    //自查自律
    function loadExaminationDetails() {

        var parms = getYearParams($('#examDt'));
        if (!parms) {
            return;
        }

        $.ajax({
            type: "POST",
            url: "invs_institution_details.do/load_examination_details",
            data: parms,
            success: function(data) {
                WeKnow.closeLoading();
                if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

                if (data.errorcode == 0) {
                    //自律自查
                    drawAutonomyExamination(data.info.autonomyExamination);
                } else if (data.errorcode == -1 ) {
                    WeKnow.errorMsg( data.errMsg );
                } else {
                    WeKnow.systemMsg('查询失败，请重新登录');
                }
            }
        });
    }

    //行政处罚
    function loadPunishDetails() {

        var parms = getYmdParams($('#punDtFrom'), $('#punDtTo'), 'yyyy-MM');
        if (!parms) {
            return;
        }

        $.ajax({
            type: "POST",
            url: "invs_institution_details.do/load_punish_details",
            data: parms,
            success: function(data) {
                WeKnow.closeLoading();
                if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

                if (data.errorcode == 0) {
                    //行政处罚
                    drawPunish(data.info.punishCount);
                } else if (data.errorcode == -1 ) {
                    WeKnow.errorMsg( data.errMsg );
                } else {
                    WeKnow.systemMsg('查询失败，请重新登录');
                }
            }
        });
    }

    /** 获取页面输入参数 */
    function getYmdParams(dtStart, dtEnd, fmt){
        var data = {};

        var institutionId = $('#institutionId').val();
        if (institutionId == undefined || institutionId.length == 0) {
            return false;
        }
        data.institutionId = institutionId;

        // 标本日期 from - to
        var $dtFrom = dtStart;
        if ( !$dtFrom.val().length ){
            WeKnow.errorMsg('请输入查询开始日期');
            $dtFrom.focus();
            return false;
        }

        var dtFrom = $dtFrom.val();
        if ( !MY_VALIDATOR.isDate(dtFrom,fmt)){
            WeKnow.errorMsg('查询开始日期格式不正确');
            $dtFrom.focus();
            return false;
        }
        data.dtFrom = dtFrom;

        // 查询日期to
        var $dtTo = dtEnd;
        if ( !$dtTo.val().length ){
            WeKnow.errorMsg('请输入查询结束日期');
            $dtTo.focus();
            return false;
        }

        var dtTo = $dtTo.val();
        if ( !MY_VALIDATOR.isDate(dtTo,fmt)){
            WeKnow.errorMsg('查询结束日期格式不正确');
            $dtTo.focus();
            return false;
        }
        data.dtTo = dtTo;

        if($dtFrom.val()>$dtTo.val()){
            WeKnow.errorMsg('开始时间不能大于结束时间');
            return false;
        }

        return data;
    }

    /** 获取页面输入参数 */
    function getYearParams(dtStart){
        var data = {};

        var institutionId = $('#institutionId').val();
        if (institutionId == undefined || institutionId.length == 0) {
            return false;
        }
        data.institutionId = institutionId;

        // 标本日期 from - to
        var $dtFrom = dtStart;
        if ( !$dtFrom.val().length ){
            WeKnow.errorMsg('请输入查询开始日期');
            $dtFrom.focus();
            return false;
        }

        var dtFrom = $dtFrom.val();
        if ( !MY_VALIDATOR.isYear(dtFrom)){
            WeKnow.errorMsg('查询开始日期格式不正确');
            $dtFrom.focus();
            return false;
        }
        data.dtFrom = dtFrom;

        return data;
    }

    function getTdElement(data, type) {
        var e = '';

        if (data && type) {
            e += '<td class="illegalColor">' + data + '</td>';
        } else {
            e += '<td>' + data + '</td>';
        }

        return e;
    }

    function getNewValue(data) {
        if (data != null && data.toString().length > 0) {
            return data;
        } else {
            return '';
        }
    }

    //转换年月日方法
    function getDate(timestamp){
        var now = new Date(timestamp);
        var yy = now.getFullYear();      //年
        var mm = now.getMonth() + 1;     //月
        var dd = now.getDate();          //日
        var clock = yy + "-";
        if(mm < 10) clock += "0";
        clock += mm + "-";
        if(dd < 10) clock += "0";
        clock += dd;

        return clock;
    }

    //机构基本信息
    function drawBaseInfo(data) {
        if(data == null) {
            return;
        }

        var technicalOffices = "诊疗科目：" + getNewValue(data.technicalOffices);
        var occupationalLicenceEndDate = getNewValue(data.occupationalLicenceEndDate);
        if (occupationalLicenceEndDate.toString().length > 0) {
            occupationalLicenceEndDate = getDate(occupationalLicenceEndDate);
        }
        occupationalLicenceEndDate = "执业许可证有效期：" + occupationalLicenceEndDate;

        document.getElementById("technicalOffices").innerHTML = technicalOffices;
        document.getElementById("occupationalLicenceEndDate").innerHTML = occupationalLicenceEndDate;
    }

    //医师、护士列表
    function drawDoctorAndNurseTable(data) {

        if (data == null || data.length == 0) {
            return;
        }

        var doctorCnt = 0;
        var nurseCnt = 0;
        var doctorEle = '';
        var nurseEle = '';
        for (var i=0; i < data.length; i++) {
            switch (data[i].role) {
                case 1:
                    doctorCnt++;
                    doctorEle += '<tr>' +
                        '<td>'+data[i].name+'</td>' +
                        '<td>'+data[i].idCard+'</td>' +
                        '<td>'+data[i].technicalTitle+'</td>' +
                        '<td>'+data[i].scopePractice+'</td>' +
                        '<td>'+data[i].qualification+'</td>' +
                        '<td>'+data[i].doctorLicence+'</td>' +
                        '</tr>';
                    break;
                case 2:
                    nurseCnt++;
                    nurseEle += '<tr>' +
                        '<td>'+data[i].name+'</td>' +
                        '<td>'+data[i].idCard+'</td>' +
                        '<td>'+data[i].technicalTitle+'</td>' +
                        '<td>'+data[i].doctorLicence+'</td>' +
                        '</tr>';
                    break;
                default:
                    break;
            }
        }

        if (doctorCnt) {
            var doctorTbody = $('#doctorTbody');
            doctorTbody.empty();
            doctorTbody.append(doctorEle);
            document.getElementById("doctorCnt").innerText = '医师：' + doctorCnt + '人';
        }

        if (nurseCnt) {
            var nurseTbody = $('#nurseTbody');
            nurseTbody.empty();
            nurseTbody.append(nurseEle)
            document.getElementById("nurseCnt").innerText  = '护士：' + nurseCnt + '人';
        }
    }

    //评分
    function drawScoreInfo(data) {
        if (data == null) {
            return;
        }

        /*document.getElementById("quality").innerText = data.quality + '分';
        document.getElementById("industry").innerText = data.industry + '分';
        document.getElementById("credit").innerText = data.credit;*/
        document.getElementById("satisfaction").innerText = data.satisfaction;
    }
    
    //满意度
    function drawSatisfaction(data) {
        if (data == undefined || data == null) {
            return;
        }

        for (var i=0; i < data.length; i++) {
            var elementId = "satisfaction" + data[i].satisfaction;
            document.getElementById(elementId).innerText = data[i].count;
        }
    }

    //诊疗行为
    function drawPrescriptionSupervision(data) {
        if (data == undefined || data == null) {
            return;
        }

        var e = '';
        e += '<tr>' + getTdElement(data.hisCount) + getTdElement(data.prescriptionsCount) + getTdElement( data.violationsCount, true) +
            '<td>' +
            '<button type="button" class="btn btn-primary btn-sm" name="preLookOver">查看</button>' +
            '</td></tr>';

        var preTbody = $('#preTbody');
        preTbody.empty();
        preTbody.append(e);

        $('button[name="preLookOver"]').on('click',function () {
            var institutionName = $('#institutionName').val();
            if (institutionName.length) {

                var otherData = 'institutionName:' + institutionName;

                // 标本日期 from - to
                var $dtFrom = $('#preDtFrom');
                if ( !$dtFrom.val().length ){
                    WeKnow.errorMsg('请输入查询开始日期');
                    $dtFrom.focus();
                    return false;
                }

                var dtFrom = $dtFrom.val();
                if ( !MY_VALIDATOR.isDate(dtFrom,'yyyy-MM-dd')){
                    WeKnow.errorMsg('查询开始日期格式不正确');
                    $dtFrom.focus();
                    return false;
                }

                // 查询日期to
                var $dtTo = $('#preDtTo');
                if ( !$dtTo.val().length ){
                    WeKnow.errorMsg('请输入查询结束日期');
                    $dtTo.focus();
                    return false;
                }

                var dtTo = $dtTo.val();
                if ( !MY_VALIDATOR.isDate(dtTo,'yyyy-MM-dd')){
                    WeKnow.errorMsg('查询结束日期格式不正确');
                    $dtTo.focus();
                    return false;
                }

                if($dtFrom.val()>$dtTo.val()){
                    WeKnow.errorMsg('开始时间不能大于结束时间');
                    return false;
                }

                otherData += ";" + "dtFrom:" + dtFrom + ";" + "dtTo:" + dtTo;

                MY_HOME_PAGE_COMMON.toWorkbench('invs_prescription_violate.do', 9, -1, otherData);
            }
        });
    }

    //消毒灭菌
    function drawAccountSupervision(data) {
        if (data == undefined || data == null) {
            return;
        }

        var e = '';
        e += '<tr>' + getTdElement(data.t10, true) + getTdElement(data.t20, true) + getTdElement(data.t30, true) +
            '<td>' +
            '<button type="button" class="btn btn-primary btn-sm" name="accLookOver">查看</button>' +
            '</td></tr>';

        var accTbody = $('#accTbody');
        accTbody.empty();
        accTbody.append(e);

        $('button[name="accLookOver"]').on('click',function () {
            var institutionName = $('#institutionName').val();
            if (institutionName.length) {

                var otherData = 'institutionName:' + institutionName;

                // 标本日期 from - to
                var $dtFrom = $('#accDtFrom');
                if ( !$dtFrom.val().length ){
                    WeKnow.errorMsg('请输入查询开始日期');
                    $dtFrom.focus();
                    return false;
                }

                var dtFrom = $dtFrom.val();
                if ( !MY_VALIDATOR.isDate(dtFrom,'yyyy-MM-dd')){
                    WeKnow.errorMsg('查询开始日期格式不正确');
                    $dtFrom.focus();
                    return false;
                }

                // 查询日期to
                var $dtTo = $('#accDtTo');
                if ( !$dtTo.val().length ){
                    WeKnow.errorMsg('请输入查询结束日期');
                    $dtTo.focus();
                    return false;
                }

                var dtTo = $dtTo.val();
                if ( !MY_VALIDATOR.isDate(dtTo,'yyyy-MM-dd')){
                    WeKnow.errorMsg('查询结束日期格式不正确');
                    $dtTo.focus();
                    return false;
                }

                if($dtFrom.val()>$dtTo.val()){
                    WeKnow.errorMsg('开始时间不能大于结束时间');
                    return false;
                }

                otherData += ";" + "dtFrom:" + dtFrom + ";" + "dtTo:" + dtTo;

                MY_HOME_PAGE_COMMON.toWorkbench('invs_summarize.do', 0, -1, otherData);
            }
        });
    }

    //自律自查
    function drawAutonomyExamination(data) {
        if (data == undefined || data == null) {
            return;
        }

        var e = '';
        e += '<tr>' + getTdElement(data.examinationCount) + getTdElement(data.rectificationCount) + getTdElement(data.reportCount) +
            '<td>' +
            '<button type="button" class="btn btn-primary btn-sm" name="examLookOver">查看</button>';
            '</td></tr>';

        var examTbody = $('#examTbody');
        examTbody.empty();
        examTbody.append(e);

        $('button[name="examLookOver"]').on('click',function () {
            MY_HOME_PAGE_COMMON.externalJump('examSystem');
        });
    }

    //行政处罚
    function drawPunish(data) {
        if (data == undefined || data == null) {
            return;
        }

        var e = '';
        e += '<tr>' + getTdElement(data, true) +
            '<td>' +
            '<button type="button" class="btn btn-primary btn-sm" name="punishLookOver">查看</button>';
            '</td></tr>';

        var punTbody = $('#punTbody');
        punTbody.empty();
        punTbody.append(e);

        $('button[name="punishLookOver"]').on('click',function () {
            MY_HOME_PAGE_COMMON.externalJump('plesSystem');
        });
    }

    //设置时间
    function setDateTime(){
        var t = null;
        t = setTimeout(time, 1000); //開始运行
        function time() {
            clearTimeout(t); //清除定时器
            dt = new Date();
            var weekDay = new Array("日", "一", "二", "三", "四", "五", "六");
            var y = dt.getFullYear();
            var mt = dt.getMonth() + 1<10?'0'+(dt.getMonth()+ 1):dt.getMonth()+ 1;
            var day = dt.getDate()<10?'0'+dt.getDate():dt.getDate();
            var h = dt.getHours()<10?'0'+dt.getHours():dt.getHours(); //获取时
            var m = dt.getMinutes()<10?'0'+dt.getMinutes():dt.getMinutes(); //获取分
            var s = dt.getSeconds()<10?'0'+dt.getSeconds():dt.getSeconds(); //获取秒
            var week = dt.getDay();
            document.getElementById("curTime").innerHTML =
                "<span class='timeFont'>"+y+"/"+mt+"/"+day+"</span>" +
                "<span class='timeFont'>星期"+weekDay[week]+"</span>" +
                "<span class='timeFont'>"+h+":"+m+":"+s+"</span>"
            t = setTimeout(time, 1000); //设定定时器，循环运行
        }
    }
    
    function initialDatepicker() {
        var today = new Date();
        var todayTxt = today.format('yyyy-MM-dd');
        var befday = new Date();
        befday.setDate(today.getDate()-6);
        var beforeDay = befday.format('yyyy-MM-dd');

        $('#preDtFrom').val(beforeDay);//开始日期初始值设置
        $('#preDtTo').val(todayTxt);//结束日期初始值设置

        $('#preDtFrom').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd',//日期格式
            yearSuffix: '年', //年的后缀
            showMonthAfterYear: true,//是否把月放在年的后面
            maxDate: (function() {
                return todayTxt;
            })(),//最大日期
            yearRange: (function() {
                // '1990:2010'
                var year2 = today.getFullYear();
                var year1 = today.getFullYear() - 100;
                return year1 + ':' + year2;
            })(),
            monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
            dayNamesMin: ['日','一','二','三','四','五','六'],
            beforeShow: function(dateText, inst){
                $("#ui-datepicker-div").removeClass('month');
            },
            onUpdatedDatepicker: function(_year, _month, _calendar) {
            },
            onSelect: function(selectedDate) {

                //开始日期大于结束日期时重设结束日期
                if (selectedDate.format('yyyy-MM-dd') > $('#preDtTo').val()) {
                    $("#preDtTo").datepicker('setDate', selectedDate);
                }

                loadPrescriptionDetails();
            }
        });

        $('#preDtTo').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd',//日期格式
            yearSuffix: '年', //年的后缀
            showMonthAfterYear: true,//是否把月放在年的后面
            maxDate: (function() {
                return todayTxt;
            })(),//最大日期
            yearRange: (function() {
                // '1990:2010'
                var year2 = today.getFullYear();
                var year1 = today.getFullYear() - 100;
                return year1 + ':' + year2;
            })(),
            monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
            dayNamesMin: ['日','一','二','三','四','五','六'],
            beforeShow: function(dateText, inst){
                $("#ui-datepicker-div").removeClass('month');
            },
            onUpdatedDatepicker: function(_year, _month, _calendar) {
            },
            onSelect: function(selectedDate) {

                //开始日期大于结束日期时重设结束日期
                if (selectedDate.format('yyyy-MM-dd') < $('#preDtFrom').val()) {
                    $("#preDtFrom").datepicker('setDate', selectedDate);
                }
                loadPrescriptionDetails();
            }
        });

        befday.setDate(today.getDate()-30);
        beforeDay = befday.format('yyyy-MM-dd');
        $('#accDtFrom').val(beforeDay);//开始日期初始值设置
        $('#accDtTo').val(todayTxt);//结束日期初始值设置

        $('#accDtFrom').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd',//日期格式
            yearSuffix: '年', //年的后缀
            showMonthAfterYear: true,//是否把月放在年的后面
            maxDate: (function() {
                return todayTxt;
            })(),//最大日期
            yearRange: (function() {
                // '1990:2010'
                var year2 = today.getFullYear();
                var year1 = today.getFullYear() - 100;
                return year1 + ':' + year2;
            })(),
            monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
            dayNamesMin: ['日','一','二','三','四','五','六'],
            beforeShow: function(dateText, inst){
                $("#ui-datepicker-div").removeClass('month');
            },
            onUpdatedDatepicker: function(_year, _month, _calendar) {
            },
            onSelect: function(selectedDate) {

                //开始日期大于结束日期时重设结束日期
                if (selectedDate.format('yyyy-MM-dd') > $('#accDtTo').val()) {
                    $("#accDtTo").datepicker('setDate', selectedDate);
                }
                loadAccountDetails();
            }
        });

        $('#accDtTo').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd',//日期格式
            yearSuffix: '年', //年的后缀
            showMonthAfterYear: true,//是否把月放在年的后面
            maxDate: (function() {
                return todayTxt;
            })(),//最大日期
            yearRange: (function() {
                // '1990:2010'
                var year2 = today.getFullYear();
                var year1 = today.getFullYear() - 100;
                return year1 + ':' + year2;
            })(),
            monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
            dayNamesMin: ['日','一','二','三','四','五','六'],
            beforeShow: function(dateText, inst){
                $("#ui-datepicker-div").removeClass('month');
            },
            onUpdatedDatepicker: function(_year, _month, _calendar) {
            },
            onSelect: function(selectedDate) {

                //开始日期大于结束日期时重设结束日期
                if (selectedDate.format('yyyy-MM-dd') < $('#accDtFrom').val()) {
                    $("#accDtFrom").datepicker('setDate', selectedDate);
                }
                loadAccountDetails();
            }
        });

        var thisYm = today.format('yyyy-MM');
        befday.setMonth(today.getMonth());
        var beforeYm = befday.format('yyyy-MM');
        $('#punDtFrom').val(beforeYm);//开始年月初始值设置
        $('#punDtTo').val(thisYm);//结束年月初始值设置

        $('#punDtFrom').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm',//日期格式
            yearSuffix: '年', //年的后缀
            showMonthAfterYear: true,//是否把月放在年的后面
            maxDate: "+0D",//最大日期
            yearRange: (function() {
                // '1990:2010'
                var year2 = today.getFullYear();
                var year1 = today.getFullYear() - 100;
                return year1 + ':' + year2;
            })(),
            monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
            showButtonPanel: true,
            closeText: '选择',
            currentText: '本月',
            isSelMon: 'true',
            beforeShow: function(dateText, inst){
                $("#ui-datepicker-div").addClass('month');
            },
            onClose: function(dateText, inst) {
                var month = $("#ui-datepicker-div .ui-datepicker-month option:selected").val();//得到选中的月份值
                var year = $("#ui-datepicker-div .ui-datepicker-year option:selected").val();//得到选中的年份值
                if ((parseInt(month)+1)  < 10) {
                    var months = '0'+ (parseInt(month)+1);
                } else {
                    months = (parseInt(month))+1;
                }
                var selectYm = year+'-'+months;
                $('#punDtFrom').val(selectYm);//给input赋值，其中要对月值加1才是实际的月份
                //开始日期大于结束日期时重设结束日期
                if (selectYm > $('#punDtTo').val()) {
                    $("#punDtTo").val(selectYm);
                }
                loadPunishDetails();
            }
        });

        $('#punDtTo').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd',//日期格式
            yearSuffix: '年', //年的后缀
            showMonthAfterYear: true,//是否把月放在年的后面
            maxDate: "+0D",//最大日期
            yearRange: (function() {
                // '1990:2010'
                var year2 = today.getFullYear();
                var year1 = today.getFullYear() - 100;
                return year1 + ':' + year2;
            })(),
            monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
            showButtonPanel: true,
            closeText: '选择',
            currentText: '本月',
            isSelMon: 'true',
            beforeShow: function(dateText, inst){
                $("#ui-datepicker-div").addClass('month');
            },
            onClose: function(dateText, inst) {
                var month = $("#ui-datepicker-div .ui-datepicker-month option:selected").val();//得到选中的月份值
                var year = $("#ui-datepicker-div .ui-datepicker-year option:selected").val();//得到选中的年份值
                if ((parseInt(month)+1)  < 10) {
                    var months = '0'+ (parseInt(month)+1);
                } else {
                    months = (parseInt(month))+1;
                }
                var selectYm = year+'-'+months;
                $('#punDtTo').val(selectYm);//给input赋值，其中要对月值加1才是实际的月份
                //开始日期大于结束日期时重设结束日期
                if (selectYm < $('#punDtFrom').val()) {
                    $("#punDtFrom").val(selectYm);
                }
                loadPunishDetails();
            }
        });

        var thisY = today.format('yyyy');
        $('#examDt').val(thisY);//开始年月初始值设置

        $('#examDt').datepicker({
            // changeMonth: true,
            changeYear: true,
            dateFormat: 'yyyyy',//日期格式
            yearSuffix: '年', //年的后缀
            showMonthAfterYear: true,//是否把月放在年的后面
            maxDate: "+0D",//最大日期
            yearRange: (function() {
                // '1990:2010'
                var year2 = today.getFullYear();
                var year1 = today.getFullYear() - 100;
                return year1 + ':' + year2;
            })(),
            monthNames: ['01','02','03','04','05','06','07','08','09','10','11','12'],
            showButtonPanel: true,
            closeText: '选择',
            currentText: '今年',
            // isSelMon: 'true',
            beforeShow: function(dateText, inst){
                $("#ui-datepicker-div").addClass('month');
            },
            onClose: function(dateText, inst) {
                var year = $("#ui-datepicker-div .ui-datepicker-year option:selected").val();//得到选中的年份值
                var selectYm = year;
                $('#examDt').val(selectYm);//给input赋值，其中要对月值加1才是实际的月份
                loadExaminationDetails();
            }
        });
    }

    return {
        setDateTime:setDateTime,
        initialDatepicker:initialDatepicker,
        loadInstitutionDetails:loadInstitutionDetails,
    }
})();

$(document).ready(function() {

    var imgSrc = document.getElementById("qrcodeTemp").getElementsByTagName("img")[0].src;
    document.getElementById("qrcodeImg").src = imgSrc;

    $(function() {
        $('[data-toggle="popover"]').popover()
    })

    $('#qrcode').popover({
        animation: true,
        trigger : 'hover',//鼠标以上时触发弹出提示框
        html: true,//开启html 为true的话，data-content里就能放html代码了
        placement: "auto top",
        container: "body",
        content: "<div class='qrcodeBig'><img class='qrcodeBigImg' src='" + imgSrc+"'></div>"
    });

    MY_INSTITUTION_DETAILS.setDateTime();

    MY_INSTITUTION_DETAILS.initialDatepicker();

    MY_INSTITUTION_DETAILS.loadInstitutionDetails($("#institutionId").val());
});